package service.impl;

import VO.BuyListVO;
import dao.BuyDao;
import dao.impl.BuyDaoImpl;
import dao.CommodityDao;
import dao.impl.CommodityDaoImpl;
import entity.BuyList;
import entity.Commodity;
import service.BuyService;

import java.util.ArrayList;
import java.util.List;
public class BuyServiceImpl implements BuyService {
    private BuyDao buyDao = new BuyDaoImpl();
    private CommodityDao commodityDao = new CommodityDaoImpl();
    @Override
    public List<BuyListVO> getBuyList() {
        List<BuyList> buyLists = buyDao.selectBuyLists();
        List<BuyListVO> buyListVOS = new ArrayList<BuyListVO>();
        for(BuyList buyList : buyLists){
            BuyListVO buyListVO = new BuyListVO();
            buyListVO.setScid(buyList.getScid());
            Commodity commodity = commodityDao.getCommodityById(buyList.getCid());
            buyListVO.setCname(commodity.getCname());
            buyListVO.setPurchasingPrice(commodity.getPurchasingPrice());
            buyListVO.setType(commodity.getType());
            buyListVO.setSum(buyList.getSum());
            buyListVO.setSid(buyList.getSid());
            buyListVO.setSuid(buyList.getSuid());
            buyListVO.setCreatetime(buyList.getCreatetime());
            buyListVO.setScstatus(buyList.getScstatus());
            buyListVOS.add(buyListVO);
        }
        return buyListVOS;
    }

    @Override
    public void updateBuyStatus(int scid) {
        buyDao.updateBuyStatus(scid);
    }

    @Override
    public void addBuyList(int cid, int sum) {
        buyDao.addBuyList(cid,sum);
    }
}
